package website.digitalocean.chapter14;

/**
 * @Author: 582895699@qq.com
 * @Desctription:
 * @Date: Created in 2023/2/13 22:42
 */
public class Dollar20Dispenser implements DispenseChain {

    protected DispenseChain dispenseChain;

    @Override
    public void sendNextChain(DispenseChain dispenseChain) {
        this.dispenseChain = dispenseChain;
    }

    @Override
    public void dispense(Currency currency) {
        int amount = currency.getAmount();
        int num = amount / 20;
        int remainder = amount % 20;
        System.out.println("Dispensing " + num + " 20$ note");
        if (remainder != 0) {
            this.dispenseChain.dispense(new Currency(remainder));
        } else {
            this.dispenseChain.dispense(currency);
        }
    }

}
